import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import * as actions from '../../actions';

class AddTodo extends Component {
    constructor() {
        super();
        this.state = {
            value: ''
        };
    }
    render() {
        const {dispatch} = this.props;
        return (
            <div>
                <form onSubmit={(e) => {
                	e.preventDefault();
                	const inputValue = this.state.value;
                	dispatch(actions.addTodo(inputValue));
                	this.setState({
                	    value: ''
                    });
                }}>
                    <input
                        placeholder="Todo Item"
                        value={this.state.value}
                        onChange={(e) => {
                        	const inputValue = e.target.value;
                        	this.setState({
                        	    value: inputValue
                            });
                        }}
                    />
                    <button type="submit">添加</button>
                </form>
            </div>
        );
    }

}

AddTodo.propTypes = {};

export default connect(null)(AddTodo);
